
var PROVINCES = [
	{
		"area_id": "1",
		"area_name": "北京市"
	},
	{
		"area_id": "2",
		"area_name": "天津市"
	},
	{
		"area_id": "3",
		"area_name": "上海市"
	},
	{
		"area_id": "4",
		"area_name": "重庆市"
	},
	{
		"area_id": "5",
		"area_name": "河北省"
	},
	{
		"area_id": "6",
		"area_name": "山西省"
	},
	{
		"area_id": "7",
		"area_name": "辽宁省"
	},
	{
		"area_id": "8",
		"area_name": "吉林省"
	},
	{
		"area_id": "9",
		"area_name": "江苏省"
	},
	{
		"area_id": "10",
		"area_name": "浙江省"
	},
	{
		"area_id": "11",
		"area_name": "安徽省"
	},
	{
		"area_id": "12",
		"area_name": "福建省"
	},
	{
		"area_id": "13",
		"area_name": "江西省"
	},
	{
		"area_id": "14",
		"area_name": "山东省"
	},
	{
		"area_id": "15",
		"area_name": "河南省"
	},
	{
		"area_id": "16",
		"area_name": "湖北省"
	},
	{
		"area_id": "17",
		"area_name": "湖南省"
	},
	{
		"area_id": "18",
		"area_name": "广东省"
	},
	{
		"area_id": "19",
		"area_name": "海南省"
	},
	{
		"area_id": "20",
		"area_name": "四川省"
	},
	{
		"area_id": "21",
		"area_name": "贵州省"
	},
	{
		"area_id": "22",
		"area_name": "云南省"
	},
	{
		"area_id": "23",
		"area_name": "陕西省"
	},
	{
		"area_id": "24",
		"area_name": "甘肃省"
	},
	{
		"area_id": "25",
		"area_name": "青海省"
	},
	{
		"area_id": "26",
		"area_name": "黑龙江省"
	},
	{
		"area_id": "27",
		"area_name": "西藏自治区"
	},
	{
		"area_id": "28",
		"area_name": "内蒙古自治区"
	},
	{
		"area_id": "29",
		"area_name": "广西壮族自治区"
	},
	{
		"area_id": "30",
		"area_name": "宁夏回族自治区"
	},
	{
		"area_id": "31",
		"area_name": "新疆维吾尔自治区"
	},
	{
		"area_id": "32",
		"area_name": "香港"
	},
	{
		"area_id": "33",
		"area_name": "澳门"
	},
	{
		"area_id": "34",
		"area_name": "台湾"
	}
];


var qQuery = new Query({container:$("#listWrap")});
var sSearch = new Search({ container : $("#searchWrap")});
//var sSelected = new Selected({container:$("#seledUl")})
var Main = RichBase.extend({
	statics : {},
	EVENTS : {
		"click" : {
			".topUl" : "onTopUlClick",
			".list_data .yujbtn" : "onSetSelected",
			".page_sub" : "bl"
		}
	},
	init : function(opt){
		var that = this;
		this.container = opt.container;
		this.prevBtn = $("#prevPageBtn");
		this.nextBtn = $("#nextPageBtn");
		sSearch.on("search",function(opt){
			that.prevBtn.addClass("disable");
			$("#whichPageNum").text(1)
			qQuery.setCurPage(0);
			qQuery.setData();
			qQuery.query(opt);
		});
		qQuery.on("no_next",function(res){
			//that.nextBtn.addClass("disable");
		});
		qQuery.on("has_next",function(res){
			that.nextBtn.removeClass("disable");
		});
		qQuery.on("query_nexta",function(last){
			var searchData = sSearch.getData();
			//console.log(searchData.province)
			qQuery.query({
				province : searchData.province,
				city : searchData.city,
				title : searchData.title,
				supplier : searchData.supplier,
				last : last
			})
		});
		qQuery.on("query_ago",function(last){
			var searchData = sSearch.getData();
			qQuery.query({
				city : searchData.city,
				province : searchData.province,
				title : searchData.title,
				supplier : searchData.supplier,
				last : last
			})
		});
		qQuery.query();
		$(".prevBtn").attr("data-last","");
	},
	
	
	onSetSelected : function(that,e){
		var target = $(e.currentTarget);
		var parent = target.parent();
		var yucln = e.target.className;
		var lid_pid = target.attr("data-pid"); 
		var aid = target.attr("data-id"); 
		var active = target.attr("data-active"); 
		//var lid_pid = parent.children("[name=lid_pid]").val();
		//if(target.attr("checked")){
		if(yucln == "yujbtn onyuj"){  // 清
			sData.set(lid_pid,aid,{
				active : 0 
			},function(data){
				//sSelected.render(data);
				//console.log(data);
			});
		}else{
			sData.set(lid_pid,aid,{
				active : 1
			},function(data){
				//console.log(data);
				//sSelected.render(data);
			})
		}
	},
	bl : function(){
		//alert("ddd")
		//$(".page_sub").attr("data","1");
		var page_size = $(".page_num_").val();
		var all = $(".nextBtn").attr("total");
		if(page_size<=all){
		var searchData = sSearch.getData();
		qQuery.query({
				province : searchData.province,
				city : searchData.city,
				title : searchData.title,
				supplier : searchData.supplier,
				currentPage : page_size
		})
		}
		else{
			return false;
		}
		
		
	},
	onTopUlClick : function(that,e){
		var tarTop = $(e.currentTarget);
		var p = tarTop.parent();
		var botW = tarTop.next();
		if(p.hasClass("selected")){
			botW.slideToggle(function(){
				p.toggleClass("selected");
			});
		}else{
			p.toggleClass("selected");
			botW.slideToggle();
		}
	}
});

$("#mlistUl").on("click",".yujbtn",function(e){
	var target = $(e.currentTarget);
	target.parents(".list_con").attr("data-ac",id);
	var type_type = $("#type_type").val();
	if(type_type=="0"){
		var url = "/call/jh_prod_n.php";	
	}
	else{
		var url = "call/jh_prod_n.php";
	}
	var active_list_a = target.parents(".list_con").find('.list_data .yujbtn');
	 $(active_list_a).each(function(){
		var active = $(this).attr("data-active");
		if(active=="1"){
			var id = $(this).attr("data-id");
			target.parents(".list_con").attr("data-ac",id);
			}
		});
	var target = $(e.currentTarget);
	var old_id = target.parents(".list_con").attr("data-ac"); 
	//console.log(old_id)
	var id = target.attr("data-id"); 
	var pid = target.attr("data-pid"); 
	var yucln = e.target.className;
	var listUl = $("#mask");
	var that = this;
	//var loading = '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">加载数据...</p><img src="images/other/loading_1.gif" alt="" /></li>';
	var loading = '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">加载数据...</p><img src="http://www.12301.cc/images/img/loading.gif" alt="" /></li>';
	var pagenavW = $("#pagenavW");
	var ttimeout =  20 * 60 * 1000;
	//var status = this.statics.queryState;
	var data = {
			action:'turnoffEvo', 
			pid:+pid,
			supplier:+id,
			rsup:+old_id
		};
	var datb = {
			action:'setEvoChain',  
			pid:+pid,
			supplier:+id,
			rsup:+old_id
		};
	var old_id = target.parents(".list_con").attr("data-ac"); 
	var conf_price = $(this).attr("data-conf_price"); 
	var ac = $(this).attr("data-active"); 
	//alert(conf_price)
	var data_conf_price = target.parents(".list_con").attr("data-conf_price"); 
		if(ac == "1"){
			var sure=confirm("确定要关闭该产品的转分销!")
			//if(conf_price=="1"){
				if (sure==true){
				PFT.Ajax({
					url : url,
					type : "GET", 
					dataType : "json",
					ttimeout : ttimeout,
					data : data,
					loading : function(){
						//listUl.html(loading);
						$("#mask").css("display","block");
						$(".img_none").css("display","block");
						//pagenavW.hide();
					},
					removeLoading : function(res){
						//listUl.html("");
						$("#mask").css("display","none");
						$(".img_none").css("display","none");
					 },
				},function(data){
						if(data.code =='200'){
						//if(data.status =='success'){
							var active_list_a = target.parents(".list_con").find('.list_data .yujbtn');
							$(active_list_a).each(function(){
								var active = $(this).attr("data-active");
								if(active=="0"){ 
									target.parents(".list_con").attr("data-ac","0");  
									$(this).parent().find(".color_a").html("");
									//target.parents(".list_con").find('.list_data .color_a').html("");
									}
							});
							target.removeClass("onyuj");
							target.attr("data-active","0");
							target.parent().find(".color_a").html("");
							//target.parents(".list_con").find('.list_data .color_a').html("");
							//alert(conf_price)
							// if(conf_price=="1"){
				
							// }
							// else{
								// target.parents(".list_con").find('.list_data .color_a').html("");
							// }
						}
						else{ 
						if(data.code =='201'){
							alert(data.msg)
							}
							
						}
					}) 
				}
				else{
					return false;
				}
			
		}else{
			var active_list_a = target.parents(".list_con").find('.list_data .yujbtn');
				PFT.Ajax({
					url : url,
					type : "GET",
					dataType : "json",
					ttimeout : ttimeout,
					data : datb,
					loading : function(){
						//listUl.html(loading);
						$("#mask").css("display","block");
						$(".img_none").css("display","block");
						
						//pagenavW.hide();
					},
					removeLoading : function(res){
						//listUl.html("");
						$("#mask").css("display","none");
						$(".img_none").css("display","none");
					 },
				},function(data){
					if(data.code =='200'){
						//if(data.status =='success'){
						var active_list_a = target.parents(".list_con").find('.list_data .yujbtn');
						$(active_list_a).each(function(){
							var active = $(this).attr("data-active");
							var pid = $(this).attr("data-id");
							if(active=="1"){ 
								$(this).removeClass("onyuj");
								$(this).parent().find(".color_a").html("");
								$(this).attr("data-active","0");
								}
							else{
								if(conf_price=="1"){
									$(this).attr("data-active","0");
									$(this).removeClass("onyuj");
									//$(this).parent().find(".color_a").html("分销价格");
									target.parent().find(".color_a").html("分销价格");
								}
								else{
									$(this).attr("data-active","0");
									$(this).removeClass("onyuj");
									$(this).parent().find(".color_a").html("");
								}
								
							}
						});
						target.addClass("onyuj");
						target.attr("data-active","1");
						//target.parent().find(".color_a").html("分销价格");
					}
					else{
						if(data.code =='202'){
							alert(data.msg)
						}
						else{
							alert(data.msg)
						}
					}
							
				})
		}
})

new Main({container:$(".RW")});

